package com.numberone.web.controller.typeList;

import com.numberone.common.annotation.Log;
import com.numberone.common.base.AjaxResult;
import com.numberone.common.enums.BusinessType;
import com.numberone.common.page.TableDataInfo;
import com.numberone.common.utils.poi.ExcelUtil;
import com.numberone.framework.web.base.BaseController;
import com.numberone.system.domain.TypeThird;
import com.numberone.system.service.ITypeThirdService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 三级类目 信息操作处理
 * 
 * @author numberone
 * @date 2020-09-25
 */
@Controller
@RequestMapping("/system/typeThird")
public class TypeThirdController extends BaseController
{
    private String prefix = "system/typeThird";
	
	@Autowired
	private ITypeThirdService typeThirdService;
	
	@RequiresPermissions("system:typeThird:view")
	@GetMapping()
	public String typeThird()
	{
	    return prefix + "/typeThird";
	}
	
	/**
	 * 查询三级类目列表
	 */
	@RequiresPermissions("system:typeThird:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TypeThird typeThird)
	{
		startPage();
        List<TypeThird> list = typeThirdService.selectTypeThirdList(typeThird);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出三级类目列表
	 */
	@RequiresPermissions("system:typeThird:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TypeThird typeThird)
    {
    	List<TypeThird> list = typeThirdService.selectTypeThirdList(typeThird);
        ExcelUtil<TypeThird> util = new ExcelUtil<TypeThird>(TypeThird.class);
        return util.exportExcel(list, "typeThird");
    }
	
	/**
	 * 新增三级类目
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存三级类目
	 */
	@RequiresPermissions("system:typeThird:add")
	@Log(title = "三级类目", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TypeThird typeThird)
	{		
		return toAjax(typeThirdService.insertTypeThird(typeThird));
	}

	/**
	 * 修改三级类目
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		TypeThird typeThird = typeThirdService.selectTypeThirdById(id);
		mmap.put("typeThird", typeThird);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存三级类目
	 */
	@RequiresPermissions("system:typeThird:edit")
	@Log(title = "三级类目", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TypeThird typeThird)
	{		
		return toAjax(typeThirdService.updateTypeThird(typeThird));
	}
	
	/**
	 * 删除三级类目
	 */
	@RequiresPermissions("system:typeThird:remove")
	@Log(title = "三级类目", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(typeThirdService.deleteTypeThirdByIds(ids));
	}
	
}
